<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function fn1(){
		var i = document.getElementById("i1");
		var d = document.getElementById("d1");
		if(isNaN(i.value)){          //判断i的值是不是数字 如果不是个数
			d.innerText = "格式错误!";   //则显示格式错误
		}else{                    //否则
			d.innerText = i.value*i.value;   //计算i的平方
		}
	}
</script>
</head>
<body>
<input type="text" id="i1" placeholder="请输入一个数字">
<input type="button" value="平方"  onclick="fn1()">
<div id="d1"></div>
</body>
</html>